var wineApp = wineApp || {};
wineApp.password = (function() {
    var initEvent = function() {
        $(document).on('click', '#getcode', function(event) {
            var username = $('#phone').val();
            getCode(username);
        }).on('click', '#change', function(event) {
            event.preventDefault();
            var code = $('#code').val();
            var phone = $('#phone').val();
            var pwd = $('#pwd').val();
            var token = wineApp.ajax.getCert();
            var epwd = CryptoJS.MD5(token + CryptoJS.MD5(pwd)).toString();
            var ajaxUrl = wineApp.CONFIG.API.changepwd;
            wineApp.ajax.post(ajaxUrl, {
                checkcode: code,
                phone: phone,
                newpwd: pwd
            }).done(function(data) {
                window.location.href = "../login.html";
            }).fail(function(data) {
                wineApp.tool.toastError(data.msg)
            })
        });
    }

    var getCode = function(phone) {
        var ajaxUrl = wineApp.CONFIG.API.code;
        wineApp.ajax.post(ajaxUrl, {
            phone: phone
        })
    }

    var initPage = function() {
        initEvent();
    }

    return {
        initPage: initPage
    }
})()

$(document).ready(function() {
    $('.wine_footer').remove();
    wineApp.common.initHeaderIcon(0, true, {
        camera: false,
        search: false
    });
    wineApp.password.initPage();
});